package com.bhy702.generator.builder.util;

import org.beetl.core.Template;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

/**
 * @author: brbai
 * @create: 2019-11-26 15:27:59
 * @description:
 */
public class GenerateUtil {


    /**
     * @Description: 生成代码文件
     * @Param: [t, filePath]
     * @return: void
     */
     public static void createFile(Template t, String filePath) throws IOException {

         File file = new File(filePath);
        //获得父级路径
        File parentFile = file.getParentFile();
        //判断父级路径是否存在，不存在就创建
        if (!parentFile.exists()) {
            parentFile.mkdirs();
        }
        //新建文件
        file.createNewFile();
        Writer writer = new FileWriter(file);
        t.renderTo(writer);
    }

}
